package com.szr.leex.po.converter;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

import com.szr.leex.po.enums.GenderEnum;

/**
 * GenderConverter
 * Created by WangChen on 2018/9/9 18:45.
 */
@Converter
public class GenderConverter implements AttributeConverter<GenderEnum, Character> {

    @Override
    public Character convertToDatabaseColumn(GenderEnum value) {
        if ( value == null ) {
            return null;
        }
        return value.getCode();
    }

    @Override
    public GenderEnum convertToEntityAttribute(Character value) {
        if ( value == null ) {
            return null;
        }
        return GenderEnum.fromCode( value );
    }
}
